package com.zhi.service.impl;

import com.zhi.dao.TeacherRepository;
import com.zhi.entity.Teacher;
import com.zhi.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;

@Service
public class TeacherServiceImpl implements TeacherService {
	
	@Autowired
	private TeacherRepository teacherRepository;

	@Override
	public List<Teacher> getEntityList() {
		return teacherRepository.findAll();
	}
	
	@Override
	public List<Object[]> getEntityListWithCodeName() {
		return teacherRepository.getEntityListWithCodeName();
	}
	

	@Override
	public Page<Teacher> getEntityListWithCodeName(Pageable pageable) {
		return teacherRepository.getEntityListWithCodeName(pageable);
	}

	@Override
	public Teacher getOne(String id) {
		return teacherRepository.getOne(id);
	}
	
	@Override
	public Teacher findOne(Teacher teacher) {
		Example<Teacher> example =Example.of(teacher);
		Optional<Teacher> optional = teacherRepository.findOne(example);
		if(optional == null) {
			return null;
		}else {
			return optional.get();
		}
	}

	@Override
	public List<Teacher> findAllById(List<String> ids){
		return teacherRepository.findAllById(ids);
	}

	@Override
	public void save(Teacher Teacher) {
		teacherRepository.save(Teacher);
	}

	@Override
	public void edit(Teacher Teacher) {
		teacherRepository.save(Teacher);
		
	}

	@Override
	public void delete(String id) {
		teacherRepository.deleteById(id);
	}

	@Override
	public Integer count(Teacher Teacher) {
		Example<Teacher> example =Example.of(Teacher);
		return (int)teacherRepository.count(example);
	}

}
